import { reqWaresInfo,reqAddOrUpdateShopCart } from "@/api";
//封装游客身份模块uuid(生成一个长期使用的随机字符串)
const state = {
    waresInfo: {},
};
const mutations = {
    GETWARESINFO(state, waresInfo) {
        state.waresInfo = waresInfo;
    },
};
const actions = {
    //获取商品详情
    async getWaresInfo({ commit }, waresId) {
        let result = await reqWaresInfo(waresId);
        if (result.code == 200) {
            commit('GETWARESINFO', result.data);
        }
    },
    //将产品添加到购物车
    async addOrUpdateShopCart({ commit }, {waresId,waresNum}) {
        //将商品加入购物车
        let result = await reqAddOrUpdateShopCart(waresId, waresNum); 
        //加入购物车成功
        if (result.code == 200) {
            return "ok"
        }else{
            //当前函数如果执行返回Promise
            return Promise.reject(new Error('false'));  
        }
            
    }
};
const getters = {
};
export default {
    state,
    mutations,
    actions,
    getters
}